/**
 * Copyright (c) 2018-2028, Joffee.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.sailmi.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sailmi.common.controller.BaseController;
import com.sailmi.common.mybatis.support.Condition;
import com.sailmi.common.mybatis.support.Query;
import com.sailmi.common.tool.api.R;
import com.sailmi.common.tool.utils.Func;
import com.sailmi.system.entity.UserEnterprise;
import com.sailmi.system.service.IUserEnterpriseService;
import com.sailmi.system.vo.UserEnterpriseVO;
import javax.validation.Valid;

import com.sailmi.system.wrapper.UserEnterpriseWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

/**
 * 用户-企业关系表 控制器
 *
 * @author sailmi
 * @since 2020-10-16
 */
@RestController
@RequestMapping("/enterprise/userenterprise")
@Tag(name = "用户-企业关系表", description = "用户-企业关系表接口")
public class UserEnterpriseController extends BaseController {

	private final IUserEnterpriseService userEnterpriseService;

	public UserEnterpriseController(IUserEnterpriseService userEnterpriseService) {
		this.userEnterpriseService = userEnterpriseService;
	}

	/**
	* 详情
	*/
	@GetMapping("/detail")
	@Operation(summary = "详情", description = "传入userEnterprise")
	public R<UserEnterpriseVO> detail(UserEnterprise userEnterprise) {
		UserEnterprise detail = userEnterpriseService.getOne(Condition.getQueryWrapper(userEnterprise));
		return R.data(UserEnterpriseWrapper.build().entityVO(detail));
	}

	/**
	* 分页 用户-企业关系表
	*/
	@GetMapping("/list")
	@Operation(summary = "分页", description = "传入userEnterprise")
	public R<IPage<UserEnterpriseVO>> list(UserEnterprise userEnterprise, Query query) {
		IPage<UserEnterprise> pages = userEnterpriseService.page(Condition.getPage(query), Condition.getQueryWrapper(userEnterprise));
		return R.data(UserEnterpriseWrapper.build().pageVO(pages));
	}

	/**
	* 自定义分页 用户-企业关系表
	*/
	@GetMapping("/page")
	@Operation(summary = "分页", description = "传入userEnterprise")
	public R<IPage<UserEnterpriseVO>> page(UserEnterpriseVO userEnterprise, Query query) {
		IPage<UserEnterpriseVO> pages = userEnterpriseService.selectUserEnterprisePage(Condition.getPage(query), userEnterprise);
		return R.data(pages);
	}

	/**
	* 新增 用户-企业关系表
	*/
	@PostMapping("/save")
	@Operation(summary = "新增", description = "传入userEnterprise")
	public R save(@Valid @RequestBody UserEnterprise userEnterprise) {
		return R.status(userEnterpriseService.save(userEnterprise));
	}

	/**
	* 修改 用户-企业关系表
	*/
	@PostMapping("/update")
	@Operation(summary = "修改", description = "传入userEnterprise")
	public R update(@Valid @RequestBody UserEnterprise userEnterprise) {
		return R.status(userEnterpriseService.updateById(userEnterprise));
	}

	/**
	* 新增或修改 用户-企业关系表
	*/
	@PostMapping("/submit")
	@Operation(summary = "新增或修改", description = "传入userEnterprise")
	public R submit(@Valid @RequestBody UserEnterprise userEnterprise) {
		return R.status(userEnterpriseService.saveOrUpdate(userEnterprise));
	}


	/**
	* 删除 用户-企业关系表
	*/
	@PostMapping("/remove")
	@Operation(summary = "删除", description = "传入ids")
	public R remove(@Parameter(name = "主键集合", required = true) @RequestParam String ids) {
		return R.status(userEnterpriseService.removeByIds(Func.toLongList(ids)));
	}


}
